package com.wang.config;

import cn.hutool.json.JSONUtil;
import com.wang.constant.ErrorCode;
import com.wang.exception.BusinessException;
import com.wang.user.model.User;
import com.wang.user.service.user.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @author：tuimao
 * @date: 2024/11/11
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    private final Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);

    @Autowired
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        try {
//            User loginUser = userService.getLoginUser();
//            if(!loginUser.getStatus()){
//                logger.info("非个人用户登录：user:{}", JSONUtil.toJsonStr(loginUser));
//                return false;
//            }
//        } catch (Exception e) {
//            logger.error("web请求异常：",e);
//            throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        logger.info("login 拦截器 postHandle");
    }
}
